<?php
/*
+--------------------------------------------------------------------------
|   Arka-Tech Web Application v1.2.0
|   ========================================
|   by Christopher Hall
|   (c) 2009 Arka-Tech Productions
|   http://arka-tech.net
|   ========================================
|   Web: http://www.SITENAME.com
|   Time: Sat, 28 Feb 2009 9:05 AM
|   Release: RmVicnVhcnkgMjAwOSBMYXVuY2ggNA==
|   Email: Arkahn@live.ca
|   Licence Info: http://www.arka-tech.net/default.php?page=license
+---------------------------------------------------------------------------
|
|   > CORE variable script ~ Edited by user.
|   > Script written by Christopher Hall
|   > Date started: 14th February 2009
|
+--------------------------------------------------------------------------
*/

/*
+---------------------------------------------------------------------------
|   To configure this software for use with your website, please uncomment
|   (remove the ) from all lines and fill in the information.
+---------------------------------------------------------------------------
*/
//------------------------------------------------------
// Require any necessary files.
//------------------------------------------------------
define('SITENAME','ATWA');
define('_ROOT','ATWA');
define('INSTALL_VERSION','NOT INSTALLED');
require_once( 'GLOBAL.php' );
class message
{
	private $content = "hello";
	
	function displayMessage()
	{
		echo $this->content;
	}
}
$my_message = new message();
$my_message->displayMessage();
/*$myList = new Lists();
foreach($my_list as $itemNo => $item)
{
	echo "{$itemNo} $item<br />\n";
}
/*function __autoload($class_name)
{
	require_once $class_name.".inc";
}
$my_hat = new Hat();*/
interface moveable
{
	function moveForward($distance);
}
class car
{
	protected $gas = 0;
	
	function __construct($amt)
	{
		$this->gas = $amt;
		echo "<p>At creation, Car contains $this->gas gallons of gas.</p>";
	}
}	
class atwaController
{
	//------------------------------------------------------
	// Version Array.
	//------------------------------------------------------
	private $registry;
	static public $cmd;
	static public function run()
	{
		$instance = new atwaController();
		$instance->init();
		$instance->handleRequest();
	}
	protected function init()
	{
		$this->registry = atwaRegistry::instance();
		$this->registry->init();
	}
	protected function handleRequest()
	{
		$cmd_r   = new ipsController_CommandResolver();
		self::$cmd     = $cmd_r->getCommand( $this->registry );
		
		IPSDebug::setMemoryDebugFlag( "Everything up until execute call", 0 );
		
		self::$cmd->execute( $this->registry );
	}
}
class atwaRegistry
{
	private static $instance;
	static public function instance()
	{
		if ( ! self::$instance )
		{
			self::$instance = new self();
		}

		return self::$instance;
	}
	static public function init()
	{
		if ( self::$initiated === TRUE )
		{
			return FALSE;
		}

		self::$initiated = TRUE;
		
		/* Load static classes */
		require ATWA_ROOT_PATH . "sources/base/core.php";

		$_MASTER	= IPSDebug::getMemoryDebugFlag();
		
		/* Load core variables */
		self::_loadCoreVariables();

		/* Load config file */
		if ( file_exists( DOC_IPS_ROOT_PATH . "conf_global.php" ) )
		{
			require DOC_IPS_ROOT_PATH . "conf_global.php";

			if ( is_array( $INFO ) )
			{
				foreach( $INFO as $key => $val )
				{
					ipsRegistry::$settings[ $key ]	= $val;
				}
			}
		}
		
		/* Make sure we're installed */
		if ( ! isset( $INFO['sql_database'] ) OR ! $INFO['sql_database'] )
		{
			/* Quick PHP version check */
			if ( ! version_compare( MIN_PHP_VERS, PHP_VERSION, '<=' ) )
			{
				print "You must be using PHP " . MIN_PHP_VERS . " or better. You are currently using: " . PHP_VERSION;
				exit();
			}

			$host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : @getenv('HTTP_HOST');
			$self = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : @getenv('PHP_SELF');
			
			if( IPS_AREA == 'admin' )
			{			
				@header("Location: http://".$host.rtrim(dirname($self), '/\\')."/install/index.php" );
			}
			else
			{
				@header("Location: http://".$host.rtrim(dirname($self), '/\\')."/admin/install/index.php" );
			}
		}

		/* Switch off dev mode you idjit */
		if ( ! defined( 'IN_DEV' ) )
		{
			define( 'IN_DEV', 0 );
		}
		
		/* Shell defined? */
		if ( ! defined( 'IPS_IS_SHELL' ) )
		{
			define( 'IPS_IS_SHELL', FALSE );
		}

		/* If this wasn't defined in the gateway file... */
		if ( ! defined( 'ALLOW_FURLS' ) )
		{
			define( 'ALLOW_FURLS', ( ipsRegistry::$settings['use_friendly_urls'] ) ? TRUE : FALSE );
		}

		/* Set it again incase a gateway turned it off */
		ipsRegistry::$settings['use_friendly_urls'] = ALLOW_FURLS;

		/* Start timer */
		IPSDebug::startTimer();

		/* Cookies... */
		IPSCookie::$sensitive_cookies = array( 'session_id', 'ipb_admin_session_id', 'member_id', 'pass_hash' );
		
		/* INIT DB */
		self::$handles['db'] = ips_DBRegistry::instance();

		/* Set DB */
		self::$handles['db']->setDB( ipsRegistry::$settings['sql_driver'] );

		/* Input set up... */
		if ( is_array( $_POST ) and count( $_POST ) )
		{
			foreach( $_POST as $key => $value )
			{
				# Skip post arrays
				if ( ! is_array( $value ) )
				{
					$_POST[ $key ] = IPSText::stripslashes( $value );
				}
			}
		}
		
    	//-----------------------------------------
    	// Clean globals, first.
    	//-----------------------------------------

		IPSLib::cleanGlobals( $_GET );
		IPSLib::cleanGlobals( $_POST );
		IPSLib::cleanGlobals( $_COOKIE );
		IPSLib::cleanGlobals( $_REQUEST );

		# GET first
		$input = IPSLib::parseIncomingRecursively( $_GET, array() );

		# Then overwrite with POST
		self::$request = IPSLib::parseIncomingRecursively( $_POST, $input );

		# Assign request method
		self::$request['request_method'] = strtolower( my_getenv('REQUEST_METHOD') );

		/* First pass of app set up. Needs to be BEFORE caches and member are set up */
		self::_fUrlInit();

		self::_manageIncomingURLs();
		
		/* _manageIncomingURLs MUST be called first!!! */
		self::_setUpAppData();

		/* Load app / coreVariables.. must be called after app Data */
		self::_loadAppCoreVariables( IPS_APP_COMPONENT );

		/* Must be called after _manageIncomingURLs */
		self::$handles['db']->getDB()->setDebugMode( ( IPS_SQL_DEBUG_MODE ) ? ( isset($_GET['debug']) ? intval($_GET['debug']) : 0 ) : 0 );

		/* Get caches */
		self::$handles['caches']   = ips_CacheRegistry::instance();

		/* Make sure all is well before we proceed */
		self::instance()->setUpSettings();

		/* Build module and application caches */
		self::instance()->checkCaches();
	
		/* Set up app specific redirects. Must be called before member/sessions setup */
		self::_parseAppResets();

		/* Re-assign member */
		self::$handles['member']   = ips_MemberRegistry::instance();

		/* Load other classes */
		require_once( IPS_ROOT_PATH    . 'sources/classes/class_localization.php' );	
		require_once( IPS_ROOT_PATH    . 'sources/classes/class_public_permissions.php' );

		self::instance()->setClass( 'class_localization', new class_localization( self::instance() ) );
		self::instance()->setClass( 'permissions'       , new classPublicPermissions( self::instance() ) );

		/* Must be called before output initiated */
		self::_getAppClass();

		if ( IPS_AREA == 'admin' )
		{
			require_once( IPS_ROOT_PATH . 'sources/classes/output/publicOutput.php' );
			require_once( IPS_ROOT_PATH . 'sources/classes/output/adminOutput.php' );
			require_once( IPS_ROOT_PATH . "sources/classes/class_admin_functions.php" );
			require_once( IPS_ROOT_PATH . 'sources/classes/class_permissions.php' );

			self::instance()->setClass( 'output'            , new adminOutput( self::instance() ) );
			self::instance()->setClass( 'adminFunctions'    , new adminFunctions( self::instance() ) );
			self::instance()->setClass( 'class_permissions' , new class_permissions( self::instance() ) );
		}
		else
		{
			require_once( IPS_ROOT_PATH . 'sources/classes/itemmarking/classItemMarking.php' );
			self::instance()->setClass( 'classItemMarking', new classItemMarking( self::instance() ) );

			require_once( IPS_ROOT_PATH  . 'sources/classes/output/publicOutput.php' );
			self::instance()->setClass( 'output', new output( self::instance(), TRUE ) );

			register_shutdown_function( 'ipsRegistry::__myDestruct' );
		}
		
		/* Add SEO templates to the output system */
		self::instance()->getClass('output')->seoTemplates = self::$_seoTemplates;

		//-----------------------------------------
		// Sort out report center early, so counts
		// and cache is right
		//-----------------------------------------
		
		$memberData	=& self::$handles['member']->fetchMemberData();
		$memberData['showReportCenter']	= false;
		
		$member_group_ids	= array( $memberData['member_group_id'] );
		$member_group_ids	= array_diff( array_merge( $member_group_ids, explode( ',', $memberData['mgroup_others'] ) ), array('') );
		$report_center		= array_diff( explode( ',', ipsRegistry::$settings['report_mod_group_access'] ), array('') );

		foreach( $report_center as $groupId )
		{
			if( in_array( $groupId, $member_group_ids ) )
			{
				$memberData['showReportCenter']	= true;
			}
		}

		if( $memberData['showReportCenter'] OR $memberData['g_is_supmod'] )
		{
			$memberData['access_report_center']	= true;

			$memberCache	= $memberData['_cache'];
			$reportsCache	= self::$handles['caches']->getCache('report_cache');

			if( ! $memberCache['report_last_updated'] || $memberCache['report_last_updated'] < $reportsCache['last_updated'] )
			{
				require_once( IPSLib::getAppDir('core') . '/sources/classes/reportLibrary.php' );
				$reports = new reportLibrary( ipsRegistry::instance() );
				$totalReports = $reports->rebuildMemberCacheArray();

				$memberCache['report_num']	= $totalReports;
				$memberData['_cache']	= $memberCache;
			}
		}

		/* More set up */
		self::_finalizeAppData();

		/* Finish fURL stuffs */
		self::_fUrlComplete();

		self::instance()->getClass('class_localization')->loadLanguageFile( array( 'public_global' ), 'core' );
		
		if ( IPS_AREA == 'admin' )
		{
			$validationStatus  = self::member()->sessionClass()->getStatus();
			$validationMessage = self::member()->sessionClass()->getMessage();

			if ( ( ipsRegistry::$request['module'] != 'login' ) AND ( ! $validationStatus ) )
			{
				//-----------------------------------------
				// Force log in
				//-----------------------------------------

				if ( ipsRegistry::$request['module'] == 'ajax' )
				{
					print "logout";
					exit();
				}
				else
				{
					ipsRegistry::$request['module'] = 'login';
					ipsRegistry::$request['core']   = 'login';

					require_once( IPSLib::getAppDir( 'core' ) . "/modules_admin/login/manualResolver.php" );
					$runme           = new admin_core_login_manualResolver( self::instance() );
					$runme->doExecute( self::instance() );

					exit();
				}
			}
		}
		else if ( IPS_AREA == 'public' )
		{
			/* Set up member */
			self::$handles['member']->finalizePublicMember();

			/* Are we banned? */
			if ( IPSMember::isBanned( 'ipAddress', self::$handles['member']->ip_address ) === TRUE )
			{
				self::instance()->getClass('output')->showError( 'you_are_banned', 2000, true );
			}

			/* Check temporary ban status */
			if( self::$handles['member']->getProperty( 'temp_ban' ) )
			{
				$ban_arr = IPSMember::processBanEntry( self::$handles['member']->getProperty( 'temp_ban' ) );

				/* No longer banned */
				if( time() >= $ban_arr['date_end'] )
				{
					self::DB()->update( 'members', array( 'temp_ban' => '' ), 'member_id=' . self::$handles['member']->getProperty( 'member_id' ) );
				}
				/* Still banned */
				else
				{
					self::getClass('output')->showError( array( 'account_susp', self::getClass( 'class_localization' )->getDate( $ban_arr['date_end'], 'LONG', 1 ) ), 1001 );
				}
			}

			/* Check server load */
			if ( ipsRegistry::$settings['load_limit'] > 0 )
			{
				$server_load	= IPSDebug::getServerLoad();

				if ( $server_load )
				{
					$loadinfo = explode( "-", $server_load );

					if ( count($loadinfo) )
					{
						self::$server_load = $loadinfo[0];

						if ( self::$server_load > ipsRegistry::$settings['load_limit'] )
						{
							self::instance()->getClass('output')->showError( 'server_too_busy', 2001 );
						}
					}
				}
			}

			if ( IPB_THIS_SCRIPT == 'public' and
				ipsRegistry::$request['section']   != 'login'  and
				ipsRegistry::$request['section']   != 'lostpass'  and
				ipsRegistry::$request['module']    != 'ajax' and
				ipsRegistry::$request['section']   != 'rss' and
				ipsRegistry::$request['section']   != 'attach' and
				ipsRegistry::$request['module']    != 'task'   and
				ipsRegistry::$request['section']   != 'captcha' )
			{
				//--------------------------------
				//  Is the board offline?
				//--------------------------------
	
				if (ipsRegistry::$settings['board_offline'] == 1 AND ! IPS_IS_SHELL )
				{
					if ( self::$handles['member']->getProperty('g_access_offline') != 1 )
					{
						ipsRegistry::$settings['no_reg'] = 1;
						self::getClass('output')->showBoardOffline();
					}
				}
			
				//-----------------------------------------
				// Do we have a display name?
				//-----------------------------------------

				if ( ! self::$handles['member']->getProperty('members_display_name') AND self::$handles['member']->getProperty('members_created_remote') )
				{
					$pmember = self::DB()->buildAndFetch( array( 'select' => '*', 'from' => 'members_partial', 'where' => "partial_member_id=" . self::$handles['member']->getProperty('member_id') ) );

					if ( $pmember['partial_member_id'] )
					{
						self::instance()->getClass('output')->silentRedirect( ipsRegistry::$settings['base_url'] . 'app=core&module=global&section=register&do=complete_login&mid='.self::$handles['member']->getProperty('member_id').'&key='.$pmember['partial_date'] );
					}
				}

				//--------------------------------
				//  Do we have permission to view
				//  the board?
				//--------------------------------

				if ( self::$handles['member']->getProperty('g_view_board') != 1 OR self::$handles['member']->getProperty('member_banned') == 1 )
				{
					self::getClass('output')->showError( 'no_view_board', 1000 );
				}

				//--------------------------------
				//  Is log in enforced?
				//--------------------------------

				if ( ( ! self::$handles['member']->getProperty('member_id') ) and (ipsRegistry::$settings['force_login'] == 1) && ipsRegistry::$request['section'] != 'register' )
				{
					ipsRegistry::$request['app']	= 'core';
					ipsRegistry::$request['module'] = 'login';
					ipsRegistry::$request['core']   = 'login';

					require_once( IPSLib::getAppDir( 'core' ) . "/modules_public/global/login.php" );
					$runme           = new public_core_global_login( self::instance() );
					$runme->doExecute( self::instance() );
					exit;
				}
			}
		}
		
		IPSDebug::setMemoryDebugFlag( "Registry initialized", $_MASTER );
	}
	$sitename = SITENAME;
	$version = array(
				'CORE' => INSTALL_VERSION,
				'Vision' => 'BETA 1'
				);
	$version = array(
				'ADMIN' => 'ArkahnX-Technology Administration User Interface (Vision)',
				);
	//------------------------------------------------------
	// Insert your name or alias here.
	//------------------------------------------------------
	const author = ''
	//------------------------------------------------------
	// Date function.
	//------------------------------------------------------
	global function clock {
		date('l jS \of F Y h:i:s A');
	}
	//------------------------------------------------------
	// Messages to welcome users to the site.
	//------------------------------------------------------
		$introtext		= "Welcome to ".$sitename." 2009.";
		$message		= "";
	//------------------------------------------------------
	// Text to display if there is nothing on the page.
	//------------------------------------------------------
		$emptytext		= "Sorry, there is nothing to display. <br />";
	//------------------------------------------------------
	// The default CSS file for the site to use.
	//------------------------------------------------------
	$CSS = "http://custom.arka-tech.net/css/Home.php";
	/*
	+--------------------------------------------------------------
	|   Options for Water.css, Ice.css, Fire.css, Earth.css, 
	|   Plant.css, Home.css, BlackFire.css, and the handicapped
	|   skins: WaterH.css, IceH.css, FireH.css, EarthH.css, 
	|   PlantH.css, HomeH.css, BlackFireH.css
	+--------------------------------------------------------------
	*/
	class init {
		const desktop = 'BETA';
	}
}
?>